module cordic_unit
#(
  parameter DATA_WIDTH = 16
)(
  //OUTPUTS
  output signed [DATA_WIDTH - 1:0] x_out,
  output signed [DATA_WIDTH - 1:0] y_out,
  output [clogb2(DATA_WIDTH)- 1:0] count,
  output ready,
  //INPUTS
  input signed [DATA_WIDTH - 1:0] x_in,
  input signed [DATA_WIDTH - 1:0] y_in,
  input signed [DATA_WIDTH - 1:0] teta_in,
  input signed [DATA_WIDTH - 1:0] arc_tg,
  input start,
  input clk,
  input rst_n
);

`include "fft_functions.v"

localparam COUNT_SIZE = clogb2(DATA_WIDTH);

wire reg_en, count_en, reg_src, count_clear;

wire [2*DATA_WIDTH - 1:0] x_in_full, y_in_full;
wire [DATA_WIDTH - 1:0] x_comp, y_comp;

//Compensation of inputs
assign x_in_full = x_in * 16'sd19890;
assign y_in_full = y_in * 16'sd19890;

assign x_comp = x_in_full[2*DATA_WIDTH - 2: DATA_WIDTH - 1];
assign y_comp = y_in_full[2*DATA_WIDTH - 2: DATA_WIDTH - 1];

cordic_datapath
#(
  .DATA_WIDTH ( DATA_WIDTH ),
  .COUNT_SIZE ( COUNT_SIZE )
)
CORDIC_DATAPATH
(
  .x_out       ( x_out       ),
  .y_out       ( y_out       ),
  .count       ( count       ),
  .ready       ( ready       ), 
  .x_in        ( x_comp      ),
  .y_in        ( y_comp      ),
  .teta_in     ( teta_in     ),
  .arc_tg      ( arc_tg      ),
  .start       ( start       ),
  .reg_en      ( reg_en      ),
  .reg_src     ( reg_src     ),
  .count_clear ( count_clear ),
  .count_en    ( count_en    ),
  .clk         ( clk         ),
  .rst_n       ( rst_n       )
);

cordic_control_unit
#(
  .DATA_WIDTH ( DATA_WIDTH ),
  .COUNT_SIZE ( COUNT_SIZE )
)
  CORDIC_CONTROLUNIT
(
  .reg_en      ( reg_en      ),
  .count_en    ( count_en    ),
  .reg_src     ( reg_src     ),
  .count_clear ( count_clear ),
  .start       ( start       ),
  .count       ( count       ),
  .clk         ( clk         ),
  .rst_n       ( rst_n       )
);

/*
function [DATA_WIDTH - 1:0] arc_tg;
  input [3:0] i;
  begin
    case (i)
      4'd0 : arc_tg = 16'd25736;
      4'd1 : arc_tg = 16'd15193;
      4'd2 : arc_tg = 16'd8027;
      4'd3 : arc_tg = 16'd4075;
      4'd4 : arc_tg = 16'd2045;
      4'd5 : arc_tg = 16'd1024;
      4'd6 : arc_tg = 16'd512;
      4'd7 : arc_tg = 16'd256;
      4'd8 : arc_tg = 16'd128;
      4'd9 : arc_tg = 16'd64;
      4'd10: arc_tg = 16'd32;
      4'd11: arc_tg = 16'd16;
      4'd12: arc_tg = 16'd8;
      4'd13: arc_tg = 16'd4;
      4'd14: arc_tg = 16'd2;
      4'd15: arc_tg = 16'd1;
    endcase
  end
endfunction
*/
endmodule
